function ChartUtils() {
};

ChartUtils.expense = function(div, data) {
  var total = 0;
  for (var i = 0, il = data.length; i < il; i++) {
    var tmp = data[i];
    total += parseFloat(tmp.value, 10);
  }
  

  for (var i = 0, il = data.length; i < il; i++) {
    var tmp = data[i];
    tmp.displayName = tmp.name;
    tmp.name += (total == 0) ? ' 0.00％' : ' ' + parseFloat((tmp.value * 100) / total, 10).toFixed(2) + '％';
  }
  div.innerHTML = '<OBJECT><EMBED WIDTH=\"98%\" HEIGHT=\"95%\" SRC=\"customswf/expense.swf?myData=' + encodeURIComponent(JSON.stringify(data)) + '\"</EMBED></OBJECT>';
};

ChartUtils.source = function(div, data) {
  var total = 0;
  for (var i = 0, il = data.length; i < il; i++) {
    var tmp = data[i];
    total += parseFloat(tmp.value, 10);
  }
  

  for (var i = 0, il = data.length; i < il; i++) {
    var tmp = data[i];
    tmp.displayName = tmp.name;
    tmp.name += (total == 0) ? ' 0.00％' : ' ' + parseFloat((tmp.value * 100) / total, 10).toFixed(2) + '％';
  }
  div.innerHTML = '<OBJECT><EMBED WIDTH=\"93%\" HEIGHT=\"95%\" SRC=\"customswf/source.swf?myData=' + encodeURIComponent(JSON.stringify(data)) + '\"</EMBED></OBJECT>';
};

ChartUtils.statsmonth = function(div, data) {
  var myData = [];
  var header = [];
  for (var i = 0, il = data.length; i < il; i++) {
    var tmp = data[i];
    var obj = { name: DlmanageUtils.monthChange(tmp.month) }
    for (var j = 0, jl = tmp.mains.length; j < jl; j++) {
      var tmp2 = tmp.mains[j];
      obj['y' + tmp2.year] = tmp2.total;
      if (i == 0) {
        header[header.length] = { displayName: tmp2.year, yField: 'y' + tmp2.year };
      }
    }
    myData[myData.length] = obj;
  }
  div.innerHTML = '<OBJECT><EMBED WIDTH=\"98%\" HEIGHT=\"95%\" SRC=\"customswf/statsmonth2.swf?myData=' + encodeURIComponent(JSON.stringify(myData)) + '&header=' + encodeURIComponent(JSON.stringify(header)) + '\"</EMBED></OBJECT>';
};

ChartUtils.statsyear = function(div, data) {
  var myData = [];
  for (var i = 0, il = data.length; i < il; i++) {
    var tmp = data[i];
    myData[myData.length] = { year: tmp.year, total: tmp.total }
  }
  div.innerHTML = '<OBJECT><EMBED WIDTH=\"98%\" HEIGHT=\"95%\" SRC=\"customswf/statsyear.swf?myData=' + encodeURIComponent(JSON.stringify(myData)) + '\"</EMBED></OBJECT>';
};
